package com.ymatou.iapi.prodstock.testcase;

import com.ymatou.iapi.liveseller.parameter.ActivityProductDto;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.LiveActivityDto;
import com.ymatou.iapi.prodstock.parameter.*;
import com.ymatou.iapi.prodstock.service.ReturnProductActivityStockCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.database.RedisDriver;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JobQueryCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.ProdStockCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.YmtProductActivityStock;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

import cn.ymatou.admin.job.parameter.JobTaskitemListBean;

import org.junit.*;
import org.junit.experimental.categories.Category;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*返还活动库存
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ReturnProductActivityStock{
	private static ReturnProductActivityStockBean returnproductactivitystockBean;
	private static ReturnProductActivityStockCall returnproductactivitystockCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("返还活动库存");
	}

	@Before
	public void caseUp() {
		returnproductactivitystockBean=new ReturnProductActivityStockBean();
		returnproductactivitystockCall=new ReturnProductActivityStockCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(returnproductactivitystockCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_001() {
		Logger.start(true,"活动商品，活动结束，商品沒卖完，活动库存清零，返高规格库存");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			int actovotyStock = 100;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actovotyStock,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			//扣活动库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(activityId,catalogs.get(0),50);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//扣活动库存数量
			List<PCatalogListDto> catalogList = preOrderReduceCatalogDto.getCatalogList();
			Integer buyCount = catalogList.get(0).getBuyCount();
			//活动开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			
			
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			String Code = returnproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			returnproductactivitystockCall.getBatchCancelResults().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(1,pp.getReturnStockStatus(),"验证返回状态");
				if(pp.getCatalogId().equals(catalogs.get(0))){
					Logger.verifyEquals(actovotyStock-buyCount,pp.getReturnStockNum(),"验证ReturnStockNum");
				}else {
					Logger.verifyEquals(actovotyStock,pp.getReturnStockNum(),"验证ReturnStockNum");
				}
			});

			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum-buyCount,inum,"验证商品规格库存与预期期望一致");
			
			//验证商品的活动库存
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(0,istocknum,"验证商品活动库存与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_002() {
		Logger.start(true,"活动商品，活动结束，商品卖完");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			Thread.sleep(3000);
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			
			//扣活动库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(activityId,catalogs.get(0),100);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//扣好活动库存数量
			List<PCatalogListDto> catalogList = preOrderReduceCatalogDto.getCatalogList();
			Integer buyCount = catalogList.get(0).getBuyCount();
			Logger.debug(buyCount);
			//活动开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum-buyCount,inum,"验证商品规格库存与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_003() {
		Logger.start(true,"普通商品，活动结束，调用接口");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			
			//扣活动库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(activityId,catalogs.get(0),100);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//扣好活动库存数量
			List<PCatalogListDto> catalogList = preOrderReduceCatalogDto.getCatalogList();
			Integer buyCount = catalogList.get(0).getBuyCount();
			Logger.debug(buyCount);
			//活动开结束
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum-buyCount,inum,"验证商品规格库存与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_004() {
		Logger.start(true,"秒杀活动商品，活动结束，调用接口");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			//CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 6d, 6, starttime);
			
			CreateLiveActivityBean createliveactivityBean = new CreateLiveActivityBean();
			LiveActivityDto LiveActivity=new LiveActivityDto();
			List<ActivityProductDto> ActivityProducts=new ArrayList<>();
			ActivityProductDto activityProductDto1 = new ActivityProductDto();
			activityProductDto1.setProductId(productId);
			activityProductDto1.setActivityPrice(7d);
			activityProductDto1.setActivityStock(100);
			activityProductDto1.setCatalogId(cids.get(0));
			ActivityProductDto activityProductDto2 = new ActivityProductDto();
			activityProductDto2.setProductId(productId);
			activityProductDto2.setActivityPrice(7d);
			activityProductDto2.setActivityStock(200);
			activityProductDto2.setCatalogId(cids.get(1));
			ActivityProducts.add(activityProductDto1);
			ActivityProducts.add(activityProductDto2);
			
			LiveActivity.setActivityProducts(ActivityProducts);
			LiveActivity.setStartTime(String.valueOf(starttime.getTime()));
			LiveActivity.setEndTime(String.valueOf(starttime.getTime()+1*60*1000));
			LiveActivity.setLiveId(createlive.getId());
			LiveActivity.setSellerId(sellerId);
			createliveactivityBean.setLiveActivity(LiveActivity);
			
			createliveactivityBean.getLiveActivity().setActivityProducts(ActivityProducts);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
		//	LiveActivityDto LiveActivity=createliveactivityBean.getLiveActivity();
			LiveRoomWapper LiveRoomWapper = new LiveRoomWapper();
			//直播秒杀活动id
			Integer liveacctivityid = LiveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
			LiveActivity.setLiveActivityId(liveacctivityid);
			//直播秒杀商品在活动中的id
			Integer LiveActivityProductId = LiveRoomWapper.selectLiveactivityproduct(liveacctivityid, LiveActivity.getActivityProducts().get(0).getProductId()).get(0).getLiveActivityProductId();
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			
			returnproductactivitystockBean.setActivityID(liveacctivityid);
			returnproductactivitystockBean.setActivityType(1);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setIsFbxProduct(false);
			returnproductactivitystockBean.setProductActivityId(LiveActivityProductId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			String Code = returnproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(cids.get(0)).getiNum();
			Logger.verifyEquals(catalogNum,inum,"验证商品规格库存与预期期望一致");
			
			Integer inum1 = new YmtCatalogsIWapper().selectCatalogsByCatalogId(cids.get(1)).getiNum();
			Logger.verifyEquals(catalogNum,inum1,"验证商品规格库存与预期期望一致");
			
			returnproductactivitystockCall.getBatchCancelResults().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品ID");
			});;
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_005() {
		Logger.start(true,"预售商品，已缴纳保证金，活动结束，返规格库存");
		try {
			AuditProductActivityStockBean auditproductactivitystockBean = new AuditProductActivityStockBean();
			ArrayList<ProductActivityStockDto> ProductActivityStockDtoList = new ArrayList<>();
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});

			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			int activityStock =100;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//活动开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			auditproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(2, YMTDateUtil.YMDTHMS_STRING);
			auditproductactivitystockBean.setEndTime(EndTime);
			auditproductactivitystockBean.setActivityID(activityId);
			auditproductactivitystockBean.setActivityType(2);
			auditproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			auditproductactivitystockBean.setUserID(sellerId);
			auditproductactivitystockBean.setProductID(productId);

			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setActivityPrice(new BigDecimal(10));
			productActivityStockDto.setCatalogId(catalogs.get(0));
			productActivityStockDto.setSku(null);
			productActivityStockDto.setStock(activityStock);
			productActivityStockDto.setEarnestDedution(10);
			productActivityStockDto.setEarnest(15);
			productActivityStockDto.setAction(1);

			ProductActivityStockDtoList.add(productActivityStockDto);
			auditproductactivitystockBean.setFBXCatalogLockList(ProductActivityStockDtoList);

			ProdStockCallService.AuditProductActivityStock(auditproductactivitystockBean);
			ProdStockCallService.UpdateProductActivityStockAction(auditproductactivitystockBean);

			//活动结束
			String BeginTime1 = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime1);
			String EndTime1 = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setEndTime(EndTime1);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setActivityType(2);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);

			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
	
			String Code = returnproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			returnproductactivitystockCall.getBatchCancelResults().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(1,pp.getReturnStockStatus(),"验证返回状态");
				if(pp.getCatalogId().equals(catalogs.get(0))){
					Logger.verifyEquals(activityStock,pp.getReturnStockNum(),"验证ReturnStockNum");
				}else {
					Logger.verifyEquals(activityStock,pp.getReturnStockNum(),"验证ReturnStockNum");
				}
			});

			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum,inum,"验证商品规格库存与预期期望一致");

			//验证商品的活动库存
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(0,istocknum,"验证商品活动库存与预期期望一致");

			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_006() {
		Logger.start(true,"预售商品，活动金未缴纳，返规格库存");
		try {
			AuditProductActivityStockBean auditproductactivitystockBean = new AuditProductActivityStockBean();
			ArrayList<ProductActivityStockDto> ProductActivityStockDtoList = new ArrayList<>();
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});

			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			int activityStock =100;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//活动开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			auditproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(2, YMTDateUtil.YMDTHMS_STRING);
			auditproductactivitystockBean.setEndTime(EndTime);
			auditproductactivitystockBean.setActivityID(activityId);
			auditproductactivitystockBean.setActivityType(2);
			auditproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			auditproductactivitystockBean.setUserID(sellerId);
			auditproductactivitystockBean.setProductID(productId);

			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setActivityPrice(new BigDecimal(10));
			productActivityStockDto.setCatalogId(catalogs.get(0));
			productActivityStockDto.setSku(null);
			productActivityStockDto.setStock(activityStock);
			productActivityStockDto.setEarnestDedution(10);
			productActivityStockDto.setEarnest(15);
			productActivityStockDto.setAction(1);

			ProductActivityStockDtoList.add(productActivityStockDto);
			auditproductactivitystockBean.setFBXCatalogLockList(ProductActivityStockDtoList);

			ProdStockCallService.AuditProductActivityStock(auditproductactivitystockBean);

			//活动开始
			String BeginTime1 = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime1);
			String EndTime1 = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setEndTime(EndTime1);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			returnproductactivitystockBean.setActivityType(2);

			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();

			String Code = returnproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			returnproductactivitystockCall.getBatchCancelResults().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(1,pp.getReturnStockStatus(),"验证返回状态");
				if(pp.getCatalogId().equals(catalogs.get(0))){
					Logger.verifyEquals(activityStock,pp.getReturnStockNum(),"验证ReturnStockNum");
				}else {
					Logger.verifyEquals(activityStock,pp.getReturnStockNum(),"验证ReturnStockNum");
				}
			});

			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum,inum,"验证商品规格库存与预期期望一致");

			//验证商品的活动库存
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(0,istocknum,"验证商品活动库存与预期期望一致");

			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_007() {
		Logger.start(true,"活动商品，库存卖完反库存,不增加库存修改结束时间");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 100;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			int actovotyStock = 100;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actovotyStock,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			
			YmtProductActivityStock YmtProductActivityStock = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0));
			Logger.comment("EndTime1:"+YmtProductActivityStock.getDendtime());
			Date e1=YmtProductActivityStock.getDendtime();
			
			//扣活动库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(activityId,catalogs.get(0),100);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//扣活动库存数量
			List<PCatalogListDto> catalogList = preOrderReduceCatalogDto.getCatalogList();
			Integer buyCount = catalogList.get(0).getBuyCount();
			//活动开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			String Code = returnproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			returnproductactivitystockCall.getBatchCancelResults().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(1,pp.getReturnStockStatus(),"验证返回状态");
				if(pp.getCatalogId().equals(catalogs.get(0))){
					Logger.verifyEquals(actovotyStock-buyCount,pp.getReturnStockNum(),"验证ReturnStockNum");
				}else {
					Logger.verifyEquals(actovotyStock,pp.getReturnStockNum(),"验证ReturnStockNum");
				}
			});

			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum-buyCount,inum,"验证商品规格库存与预期期望一致");
			
			//验证商品的活动库存
			YmtProductActivityStock = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0));
			Logger.verifyEquals(0,YmtProductActivityStock.getIstocknum(),"验证商品活动库存与预期期望一致");
			Date e2=YmtProductActivityStock.getDendtime();
			Logger.comment("EndTime2:"+YmtProductActivityStock.getDendtime());
			Logger.verifyNotEquals(e1, e2, "验证时间更新");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_008() {
		Logger.start(true,"活动商品，活动结束，商品沒卖完，活动库存清零，返高规格库存-通知JOB删除结束任务，同时发送一条MQ消息");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			int actovotyStock = 100;
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actovotyStock,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			//扣活动库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(activityId,catalogs.get(0),50);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//扣活动库存数量
			List<PCatalogListDto> catalogList = preOrderReduceCatalogDto.getCatalogList();
			Integer buyCount = catalogList.get(0).getBuyCount();
			//活动开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			String Code = returnproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			returnproductactivitystockCall.getBatchCancelResults().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(1,pp.getReturnStockStatus(),"验证返回状态");
				if(pp.getCatalogId().equals(catalogs.get(0))){
					Logger.verifyEquals(actovotyStock-buyCount,pp.getReturnStockNum(),"验证ReturnStockNum");
				}else {
					Logger.verifyEquals(actovotyStock,pp.getReturnStockNum(),"验证ReturnStockNum");
				}
			});

			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum-buyCount,inum,"验证商品规格库存与预期期望一致");
			
			//验证商品的活动库存
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(0,istocknum,"验证商品活动库存与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
			MessageListBean = MqQueryCallService.initActivityStatusChange(productId);
			joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Logger.verifyEquals(1, joa.size(), "验证发送MQ-activity_status_change");
			
			//验证end
			JobTaskitemListBean jobListBean = JobQueryCallService.initActivityProductStartOrEnd(productId,activityId,"END");
			joa = JobQueryCallService.GetJobTasks(jobListBean);
			if(joa.size()>0){
				Thread.sleep(5000);
				 joa = JobQueryCallService.GetJobTasks(jobListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Logger.verifyEquals(0, joa.size(), "验证end记录删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_009() {
		Logger.start(true,"秒杀活动商品，活动结束，调用接口 查询redis");
		try {
			
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			//CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 6d, 6, starttime);
			
			CreateLiveActivityBean createliveactivityBean = new CreateLiveActivityBean();
			LiveActivityDto LiveActivity=new LiveActivityDto();
			List<ActivityProductDto> ActivityProducts=new ArrayList<>();
			ActivityProductDto activityProductDto1 = new ActivityProductDto();
			activityProductDto1.setProductId(productId);
			activityProductDto1.setActivityPrice(7d);
			activityProductDto1.setActivityStock(100);
			activityProductDto1.setCatalogId(cids.get(0));
			ActivityProductDto activityProductDto2 = new ActivityProductDto();
			activityProductDto2.setProductId(productId);
			activityProductDto2.setActivityPrice(7d);
			activityProductDto2.setActivityStock(200);
			activityProductDto2.setCatalogId(cids.get(1));
			ActivityProducts.add(activityProductDto1);
			ActivityProducts.add(activityProductDto2);
			
			LiveActivity.setActivityProducts(ActivityProducts);
			LiveActivity.setStartTime(String.valueOf(starttime.getTime()));
			LiveActivity.setEndTime(String.valueOf(starttime.getTime()+1*60*1000));
			LiveActivity.setLiveId(createlive.getId());
			LiveActivity.setSellerId(sellerId);
			createliveactivityBean.setLiveActivity(LiveActivity);
			
			createliveactivityBean.getLiveActivity().setActivityProducts(ActivityProducts);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
		//	LiveActivityDto LiveActivity=createliveactivityBean.getLiveActivity();
			LiveRoomWapper LiveRoomWapper = new LiveRoomWapper();
			//直播秒杀活动id
			Integer liveacctivityid = LiveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
			LiveActivity.setLiveActivityId(liveacctivityid);
			//直播秒杀商品在活动中的id
			Integer LiveActivityProductId = LiveRoomWapper.selectLiveactivityproduct(liveacctivityid, LiveActivity.getActivityProducts().get(0).getProductId()).get(0).getLiveActivityProductId();
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			//添加秒杀商品数据
			ProductManagerCallServiceV2.addSecKillStock(LiveActivityProductId,productId, sellerId, true);
			
			
			returnproductactivitystockBean.setActivityID(liveacctivityid);
			returnproductactivitystockBean.setActivityType(1);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setIsFbxProduct(false);
			returnproductactivitystockBean.setProductActivityId(LiveActivityProductId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			String Code = returnproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(cids.get(0)).getiNum();
			Logger.verifyEquals(catalogNum,inum,"验证商品规格库存与预期期望一致");
			
			Integer inum1 = new YmtCatalogsIWapper().selectCatalogsByCatalogId(cids.get(1)).getiNum();
			Logger.verifyEquals(catalogNum,inum1,"验证商品规格库存与预期期望一致");
			
			returnproductactivitystockCall.getBatchCancelResults().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品ID");
			});;
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
			RedisDriver rd = new RedisDriver("group1",EnvSetup.getSystemUrl("sentinel"));
			String key="SecStock:"+LiveActivityProductId+":"+cids.get(0);
			Logger.comment("获取redis，key为："+key+"值为："+rd.getValue(key));
//			Logger.verifyEquals(rd.getValue(key),auditproductactivitystockBean.getFBXCatalogLockList().get(0).getStock()+"", "验证redis库存");
			
			
		} catch (Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReturnProductActivityStock_010() {
		Logger.start(true,"活动商品，活动结束，商品卖了50 验证redis为50，然后返还库存");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			System.out.println(catalogs.toString());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//添加秒杀商品数据
			ProductManagerCallServiceV2.addSecKillStock(activityId,productId, sellerId, true);
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			
			//扣活动库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(activityId,catalogs.get(0),50);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//扣好活动库存数量
			List<PCatalogListDto> catalogList = preOrderReduceCatalogDto.getCatalogList();
			Integer buyCount = catalogList.get(0).getBuyCount();
			Logger.debug(buyCount);
			RedisDriver rd = new RedisDriver("group1",EnvSetup.getSystemUrl("sentinel"));
			String key="SecStock:"+aids.get(0)+":"+catalogs.get(0);
			Logger.comment("获取redis，key为："+key+"值为："+rd.getValue(key));
			Logger.verifyEquals(rd.getValue(key), "50", "当前库存为50");
			//活动开始
			
			Thread.sleep(2000);
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			returnproductactivitystockBean.setEndTime(EndTime);
			returnproductactivitystockBean.setActivityID(activityId);
			returnproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			returnproductactivitystockBean.setUserID(sellerId);
			returnproductactivitystockBean.setProductID(productId);
			returnproductactivitystockBean.setStoreType(-1);
			
			returnproductactivitystockCall.setData(returnproductactivitystockBean);
			returnproductactivitystockCall.callService();
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
			
			Logger.comment("获取redis，key为："+key+"值为："+rd.getValue(key));
			Logger.verifyEquals(rd.getValue(key), null, "返还活动库存，为0");
			System.out.println(catalogs.get(0));
			Thread.sleep(10000);
			//验证商品的规格库存
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum-buyCount,inum,"验证商品规格库存与预期期望一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
		
	}
	
	
}



